// Copyright DustedPixels.com 2008. All rights reserved.

package com.dustedpixels.dcel.parser;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import com.dustedpixels.dcel.tree.Tree;

/**
 * @author micapolos@gmail.com (Michal Pociecha-Los)
 */
public final class DcelParser {
  public static Tree parse(Reader reader) throws Exception {
    return (Tree) new parser(new Yylex(reader)).parse().value;
  }
  
  public static Tree parse(String name) throws Exception {
    InputStream inputStream = 
        DcelParser.class.getResourceAsStream("/" + name.replace('.', '/') + ".dcel");
    try {
      Reader reader = new InputStreamReader(inputStream, "UTF-8");
      return parse(reader);
    } finally {
      inputStream.close();
    }
  }
  
  public static void main(String[] args) throws Exception {
    Tree tree = parse("And");
    System.out.println(tree.packageDecl.name);
  }
}
